<template>
	<div class="page">
		<Notice></Notice>
		<u-navbar :is-back="true" :title="!!params.id?'编辑专题':'添加专题'"></u-navbar>
		<u-sticky>
			<div class="name">
				<u-input v-model="params.title" type="text" placeholder="请输入专题名称" placeholder-style="color: #666" />
			</div>
			<u-tabs class="tabs" :list="tabs" :is-scroll="false" :current="tabIndex" bg-color="#F2F3F7" @change="tabChange"></u-tabs>
		</u-sticky>
		<!-- 关键词设置 -->
		<div class="content-1" v-show="tabIndex==0">
			<div class="block">
				<div class="warn">您还可设置<span class="count">{{wordCount}}</span>个主体词</div>
				<div class="title">品牌词<span class="red">*</span></div>
				<div class="box" @click="toInputPage('品牌词')">
					<div class="tags" v-if="params.word_1.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.word_1" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">主题词</div>
				<div class="box" @click="toInputPage('主题词')">
					<div class="tags" v-if="params.word_2.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.word_2" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">事件词</div>
				<div class="box" @click="toInputPage('事件词')">
					<div class="tags" v-if="params.word_3.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.word_3" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block">
				<div class="title">歧义词</div>
				<div class="box" @click="toInputPage('歧义词')">
					<div class="tags" v-if="params.amb_word.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.amb_word" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="line"></div>
			<u-collapse-item class="row" title="排除设置">
				<div class="block">
					<div class="title">排除词</div>
					<div class="box" @click="toInputPage('排除词')">
						<div class="tags" v-if="params.exclude_word.length>0">
							<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.exclude_word" :key="index" />
						</div>
						<div class="tip" v-else>请输入</div>
					</div>
				</div>
				<div class="block">
					<div class="title">排除作者</div>
					<div class="box" @click="toInputPage('排除作者')">
						<div class="tags" v-if="params.exclude_author.length>0">
							<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.exclude_author" :key="index" />
						</div>
						<div class="tip" v-else>请输入</div>
					</div>
				</div>
				<div class="block">
					<div class="title">排除域名</div>
					<div class="box" @click="toInputPage('排除域名')">
						<div class="tags" v-if="params.exclude_domain.length>0">
							<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.exclude_domain" :key="index" />
						</div>
						<div class="tip" v-else>请输入</div>
					</div>
				</div>
				<div class="block">
					<div class="title">排除频道</div>
					<div class="box" @click="toInputPage('排除频道')">
						<div class="tags" v-if="params.exclude_channel.length>0">
							<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.exclude_channel" :key="index" />
						</div>
						<div class="tip" v-else>请输入</div>
					</div>
				</div>
			</u-collapse-item>
			<div class="line"></div>
			<div class="select-row flex">
				<span class="title">定向设置 <u-icon name="question-circle" size="32" color="#999" style="margin-right: 10rpx;" @click="isAut=true"></u-icon></span>
				<span class="select-value flex" @click="isSubcate=!isSubcate">
					<span class="select-value-text">{{ subcates[subcateIndex].label }}</span>
					<u-icon name="arrow-down" color="#666" size="28"></u-icon>
				</span>
				<div class="cate-box" v-show="isSubcate">
					<div class="cate-item" v-for="(item,index) in subcates" :key="item.value" @click="subcateSelect(index)">{{ item.label }}</div>
				</div>
			</div>
			<div class="block block-2" v-if="subcateIndex==0">
				<div class="box" @click="toInputPage('指定站点')">
					<div class="tags" v-if="params.filter_channel.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.filter_channel" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block block-2" v-else-if="subcateIndex==1">
				<div class="box" @click="toInputPage('指定作者')">
					<div class="tags" v-if="params.filter_source.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.filter_source" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="checks-row checks-row-2" v-else-if="subcateIndex==2">
				<u-checkbox v-model="mediaTypeAll" @change="checksMediaTypeAll" :name="0">全部</u-checkbox>
				<u-checkbox-group @change="checksMediaType">
					<u-checkbox 
						v-model="item.checked" 
						v-for="(item, index) in mediaOptions" :key="index" 
						:name="item.value"
					>{{item.label}}</u-checkbox>
				</u-checkbox-group>
			</div>
			<div class="block block-2" v-else-if="subcateIndex==3">
				<div class="box" @click="toInputPage('信源范围')">
					<div class="tags" v-if="params.filter_repost_source.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.filter_repost_source" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
			<div class="block block-2" v-else-if="subcateIndex==4">
				<div class="box" @click="toInputPage('指定账号')">
					<div class="tags" v-if="params.filter_source_id.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.filter_source_id" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
		</div>
		<!-- 精准设置 -->
		<div class="content-2" v-show="tabIndex==1">
			<div class="check-row flex">
				<u-checkbox v-model="is_word_spacing">词距范围</u-checkbox>
				<u-number-box v-model="params.word_spacing"></u-number-box>
			</div>
			<div class="check-row flex">
				<u-checkbox v-model="is_brand_pos">品牌词首现位置</u-checkbox>
				<u-number-box v-model="params.brand_pos"></u-number-box>
			</div>
			<div class="check-row flex">
				<u-checkbox v-model="params.unique_area">唯一地域</u-checkbox>
			</div>
			<div class="check-row flex">
				<u-checkbox v-model="params.wb_time_point">微博时间点过滤</u-checkbox>
			</div>
			<div class="check-row flex">
				<u-checkbox v-model="params.only_title">仅标题匹配</u-checkbox>
			</div>
			
			<div class="check-row flex">
				<u-checkbox v-model="params.ignore_wb_location">忽略微博位置中的关键词</u-checkbox>
			</div>
			<div class="check-row flex">
				<u-checkbox v-model="params.ignore_wb_hashtag">忽略微博话题中的关键词</u-checkbox>
			</div>
			<div class="check-row flex">
				<u-checkbox v-model="params.ignore_wb_mentions">忽略微博@中的关键词</u-checkbox>
			</div>
			<div class="checks-row">
				<div class="title">倾向性</div>
				<u-checkbox v-model="sentiment_all" @change="checksTendAll" :name="0">全部</u-checkbox>
				<u-checkbox-group @change="checksTend">
					<u-checkbox 
						v-model="item.checked" 
						v-for="(item, index) in tendOptions" :key="index" 
						:name="item.value"
					>{{item.label}}</u-checkbox>
				</u-checkbox-group>
			</div>
			<div class="checks-row">
				<div class="title">文章类型</div>
				<u-checkbox v-model="filter_type_all" @change="checksArticleTypeAll"  :name="0">全部</u-checkbox>
				<u-checkbox-group @change="checksArticleType">
					<u-checkbox 
						v-model="item.checked" 
						v-for="(item, index) in articleTypeOptions" :key="index" 
						:name="item.value"
					>{{item.label}}</u-checkbox>
				</u-checkbox-group>
			</div>
			<div class="checks-row">
				<div class="title">微博认证</div>
				<u-checkbox v-model="verified_type_all" @change="checksWeiboUserAll" :name="0">全部</u-checkbox>
				<u-checkbox-group @change="checksWeiboUser">
					<u-checkbox 
						v-model="item.checked" 
						v-for="(item, index) in weiboUserOptions" :key="index" 
						:name="item.value"
					>{{item.label}}</u-checkbox>
				</u-checkbox-group>
			</div>
			<div class="block">
				<div class="title">地域范围</div>
				<div class="box" @click="toInputPage('地域范围')">
					<div class="tags" v-if="params.filter_area.length>0">
						<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.filter_area" :key="index" />
					</div>
					<div class="tip" v-else>请输入</div>
				</div>
			</div>
		</div>
		<!-- 预警设置 -->
		<div class="content-3" v-show="tabIndex==2">
			<div class="toggle-row flex">
				<span class="title">人工预警</span>
				<span class="value">未开启</span>
			</div>
			<div class="toggle-row flex">
				<span class="title">公共预警</span>
				<u-switch v-model="params.warn" size="36"></u-switch>
			</div>
			<div class="checks-row" v-if="params.warn">
				<div class="title">预警级别</div>
				<u-radio-group v-model="params.warn_level" @change="checksWarn" shape="square">
					<u-radio 
						v-for="(item, index) in warningOptionsSubject" :key="index" 
						:name="item.value"
					>
						{{item.label}}
					</u-radio>
				</u-radio-group>
			</div>
			<div class="line"></div>
			<div class="toggle-row flex">
				<span class="title">自定义预警</span>
				<u-switch v-model="params.custom" size="36"></u-switch>
			</div>
			<div v-if="params.custom">
				<div class="checks-row">
					<div class="title">媒体类型</div>
					<u-checkbox v-model="mediaTypeAll_warn" @change="checksWarnMediaTypeAll"  :name="0">全部</u-checkbox>
					<u-checkbox-group @change="checksWarnMediaType">
						<u-checkbox 
							v-model="item.checked" 
							v-for="(item, index) in warn_mediaOptions" :key="index" 
							:name="item.value"
						>{{item.label}}</u-checkbox>
					</u-checkbox-group>
				</div>
				<div class="checks-row">
					<div class="title">预警文章类型</div>
					<u-checkbox v-model="filter_type_all_warn" @change="checksWarnArticleTypeAll"  :name="0">全部</u-checkbox>
					<u-checkbox-group @change="checksWarnArticleType">
						<u-checkbox 
							v-model="item.checked" 
							v-for="(item, index) in warn_articleTypeOptions" :key="index" 
							:name="item.value"
						>{{item.label}}</u-checkbox>
					</u-checkbox-group>
				</div>
				<div class="checks-row">
					<div class="title">倾向性</div>
					<u-checkbox v-model="sentiment_all_warn" @change="checksWarnTendAll" :name="0">全部</u-checkbox>
					<u-checkbox-group @change="checksWarnTend">
						<u-checkbox 
							v-model="item.checked" 
							v-for="(item, index) in warn_tendOptions" :key="index" 
							:name="item.value"
						>{{item.label}}</u-checkbox>
					</u-checkbox-group>
				</div>
				<div class="checks-row">
					<div class="title">噪音过滤</div>
					<u-radio-group v-model="params.custom_noise" @change="checksWarnNoise">
						<u-radio  
							v-for="(item, index) in noiseOptions" :key="index" 
							:name="item.value"
						>{{item.label}}</u-radio >
					</u-radio-group>
				</div>
				<div class="block block-2">
					<div class="title">预警词</div>
					<div class="box" @click="toInputPage('预警词')">
						<div class="tags" v-if="params.custom_words.length>0">
							<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.custom_words" :key="index" />
						</div>
						<div class="tip" v-else>请输入</div>
					</div>
				</div>
				<div class="block block-2">
					<div class="title">排除词</div>
					<div class="box" @click="toInputPage('预警排除词')">
						<div class="tags" v-if="params.custom_exclude.length>0">
							<u-tag class="tag" :text="item" mode="plain" v-for="(item, index) in params.custom_exclude" :key="index" />
						</div>
						<div class="tip" v-else>请输入</div>
					</div>
				</div>
			</div>
			<div class="line"></div>
			<div class="toggle-row flex">
				<span class="title">异常预警<span class="subtitle">设置完成次日生效</span></span>
				<u-switch v-model="params.abnormal_warn" size="36"></u-switch>
			</div>
			<div v-if="params.abnormal_warn">
				<div class="checks-row">
					<div class="title">倾向性</div>
					<u-checkbox v-model="sentiment_all_warn2" @change="checksWarnTendAll2" :name="0">全部</u-checkbox>
					<u-checkbox-group @change="checksWarnTend2">
						<u-checkbox 
							v-model="item.checked" 
							v-for="(item, index) in warn_tendOptions2" :key="index" 
							:name="item.value"
						>{{item.label}}</u-checkbox>
					</u-checkbox-group>
				</div>
				<div class="row">
					<div class="title">预警阈值</div>
					<div class="row-text flex">一个小时内超过前七天相应时段平均数量
						<u-input v-model="params.abnormal_threshold" type="number" placeholder="" :clearable="false" :border="true" style="padding: 0 5rpx;margin: 0 5rpx;" />
						%时预警</div>
				</div>
			</div>
		</div>
	
		<div class="option">
			<div class="option-a flex" v-show="tabIndex == 1">
				<span>按以上规则进数据</span>
				<u-switch v-model="params.precision" size="36"></u-switch>
			</div>
			<div class="option-b flex">
				<div class="l" @click="isDes=true">
					<u-icon name="question-circle" size="32" color="#999" style="margin-right: 10rpx;"></u-icon>
					说明
				</div>
				<div class="r">
					<u-button type="primary" @click="save">保存专题</u-button>
				</div>
			</div>
		</div>
		<!-- 说明 -->
		<u-popup v-model="isDes" mode="bottom" border-radius="14">
			<view class="des">
				<div class="top"><u-icon class="icon" name="arrow-down" size="32" @click="isDes=false"></u-icon> 说明</div>
				<scroll-view scroll-y="true" class="container">
					<div class="title">品牌词</div>
					<div class="text">
						<div>1.输入与企业相关的品牌词，可输入多个关键词，词与词之间为“或”关系。</div>
						<div>2.品牌词、主体词、事件词之间为“与”关系，信息同时匹配3组关键词才会被监测。</div>
						<div>3.现有特殊校验字符 < > |。</div>
					</div>
					<div class="title">主题词</div>
					<div class="text">
						<div>1.可输入多个主题词，词与词之间为“或”关系。</div>
						<div>2.品牌词、关键词一、关键词二之间为“与”关系，信息同时匹配3组关键词才会被监测。</div>
						<div>3.提供智能推荐标签，包含行业涉及主体词，精准识别信息。</div>
						<div>4.现有特殊校验字符 < > |。</div>
					</div>
					<div class="title">事件词</div>
					<div class="text">
						<div>1.可输入多个事件词，词与词之间为“或”关系。</div>
						<div>2.品牌词、关键词一、关键词二之间为“与”关系，信息同时匹配3组关键词才会被监测。</div>
						<div>3.提供智能推荐标签，包含行业涉及主体词，精准识别信息。</div>
						<div>4.现有特殊校验字符 < > |。</div>
					</div>
					<div class="title">歧义词</div>
					<div class="text">
						<div>1.与关键词相歧义的词，如品牌词为小米，歧义为小米粥。命中关键词的信息，将参考其它关键词的命中概率，再决定是否进入系统。</div>
						<div>2.可输入多个关键词，词之间以空格间隔，词与词之间为“或”关系。</div>
						<div>3.现有特殊校验字符 < > |。</div>
					</div>
				</scroll-view>
			</view>
		</u-popup>
		<u-popup v-model="isAut" mode="bottom" border-radius="14">
			<view class="des">
				<div class="top"><u-icon class="icon" name="arrow-down" size="32" @click="isAut=false"></u-icon> 定向说明</div>
				<div class="container">
					<div class="title">指定作者</div>
					<div class="text">
						<div>域名-昵称</div>
					</div>
					<div class="title">指定账号</div>
					<div class="text">
						<div>昵称-账号</div>
					</div>
				</div>
			</view>
		</u-popup>
		<wordInput v-if="isInputPage" :flag="kwType" @sendKeyWords="getWordData"></wordInput>
		<u-toast ref="uToast" />
	</div>
</template>

<script>
import wordInput from "@/components/wordInput.vue";
import { addSubject, editSubject, subjectDetail, delGroup, delSubject } from "@/api/subject.js";

export default {
	components: {
		wordInput,
	},
	data() {
		return {
			isDes: false,
			tabs: [
				{
					name: "关键词设置"
				}, {
					name: "精准设置"
				}, {
					name: "预警设置",
				},
			],
			tabIndex: 0,
			wordCount: 0,
			params: {
				pid: "",
				title: "",  //专题名称
				word_1: [],  //品牌词
				word_2: [],  //主题词
				word_3: [],  //事件词
				user_logic: "",  //关键词表达式
				amb_word: [],
				exclude_word: [],  //排除词
				exclude_author: [],  //排除作者
				exclude_domain: [],  //排除域名
				exclude_channel: [],  //排除频道
				amb_word: [],  //歧义词
				match_fields: [],  //匹配位置
				filter_media: [],  //定向媒体类型
				filter_domain: [],  //定向域名
				filter_channel: [],  //定向频道
				filter_source: [],  //定向发帖人
				filter_source_id: [],  //定向发帖人id
				filter_repost_source: [],  //新闻原发帖人
				user_ip_region: "",  //用户IP属地
				user_location: "",  //用户注册地
				
				word_spacing: 0,  //词距范围
				brand_pos: 0,  //品牌词首现位置
				unique_area: false,  //唯一地域
				wb_time_point: false,  //微博时间点过滤
				only_title: false,  //是否仅匹配标题
				ignore_wb_location: false,  //忽略微博位置中命中关键词的数据
				ignore_wb_hashtag: false,  //忽略微博话题中的关键词
				ignore_wb_mentions: false,  //忽略微博@的命中的关键词
				filter_area: [],  //地域标签
				filter_area_type: [],  //地域匹配的范围
				sentiment: [0],  //倾向性
				filter_type: [0],  //文章类型
				verified_type: [0],  //微博认证
				precision: false,

				warn: true,  //榜单预警是否开启
				warn_level: 1,  //榜单预警级别
				custom: false,  //自定义预警是否开启
				custom_media: [0],  //自定义预警媒体类型
				custom_type: [0],  //发布类型
				custom_noise: 0,  //噪音过滤
				custom_sentiment: [2],  //自定义倾向性
				custom_words: [],  //自定义预警词
				custom_exclude: [],  //自定义排除词
				abnormal_warn: false,  //异常预警是否开启
				abnormal_sentiment: [1],  //异常倾向性
				abnormal_threshold: 30,  //预警阈值 %
			},
			subcates: [
				{
					label: "指定站点",
					value: 1,
				},
				{
					label: "指定作者",
					value: 2,
				},
				{
					label: "媒体类型",
					value: 3,
				},
				{
					label: "信源范围",
					value: 4,
				},
				{
					label: "指定账号",
					value: 5,
				}
			],
			isSubcate: false,
			subcateIndex: 0,
			kwType: "",
			// 精准设置
			tendOptions: [
				{ label: "正面", value: 1, checked:false },
				{ label: "负面", value: 3, checked:false },
				{ label: "中性", value: 2, checked:false },
			],
			articleTypeOptions: [
				{ label: "原创", value: 1, checked:false },
				{ label: "转发", value: 2, checked:false },
				{ label: "评论", value: 7, checked:false },
				{ label: "弹幕", value: 8, checked:false },
			],
			weiboUserOptions: [
				{ label: "蓝V", value: 3, checked:false },
				{ label: "橙V", value: 2, checked:false },
				{ label: "普通用户", value: 1, checked:false },
			],
			sentiment_all: false,
			sentiment: [],
			filter_type_all: false,
			filter_type: [],
			verified_type_all: false,
			verified_type: [],
			// 预警设置
			warningOptionsSubject: [
				{ label: "宽松", value: 2, checked:false },
				{ label: "标准", value: 1, checked:false },
				{ label: "严格", value: 3, checked:false },
			],
			warn_tendOptions: [
				{ label: "正面", value: 1, checked:false },
				{ label: "负面", value: 3, checked:true },
				{ label: "中性", value: 2, checked:false },
			],
			warn_articleTypeOptions: [
				{ label: "原创", value: 1, checked:false },
				{ label: "转发", value: 2, checked:false },
				{ label: "评论", value: 7, checked:false },
				{ label: "弹幕", value: 8, checked:false },
			],
			mediaOptions: [
				{ label: "新闻", value: "01", checked:false },
				{ label: "平媒", value: "0105", checked:false },
				{ label: "论坛", value: "02", checked:false },
				{ label: "博客", value: "03", checked:false },
				{ label: "微博", value: "04", checked:false },
				{ label: "新浪微博", value: "0401", checked:false },
				{ label: "微信", value: "06", checked:false },
				{ label: "视频", value: "07", checked:false },
				{ label: "长微博", value: "08", checked:false },
				{ label: "APP", value: "0109", checked:false },
				{ label: "短视频", value: "11", checked:false },
			],
			warn_mediaOptions: [
				{ label: "新闻", value: "01", checked:false },
				{ label: "平媒", value: "0105", checked:false },
				{ label: "论坛", value: "02", checked:false },
				{ label: "博客", value: "03", checked:false },
				{ label: "微博", value: "04", checked:false },
				{ label: "新浪微博", value: "0401", checked:false },
				{ label: "微信", value: "06", checked:false },
				{ label: "视频", value: "07", checked:false },
				{ label: "长微博", value: "08", checked:false },
				{ label: "APP", value: "0109", checked:false },
				{ label: "短视频", value: "11", checked:false },
			],
			mediaTypeAll: false,
			noiseOptions: [
				{ label: "全部", value: 0, checked:false },	
				{ label: "正常", value: 1, checked:false },	
				{ label: "过滤", value: 3, checked:true },
			],
			sentiment_all_warn: false,
			filter_type_all_warn: false,
			mediaTypeAll_warn: false,
			warn_tendOptions2: [
				{ label: "正面", value: 1, checked:true },
				{ label: "负面", value: 3, checked:false },
				{ label: "中性", value: 2, checked:false },
			],
			sentiment_all_warn2: false,
			isAut: false
		};
	},
	onLoad: function (option) {
		this.params.pid = option.pid;
		let id = option.id;
		if(!!id){
			this.params.id = id;
			uni.showLoading({title: "读取中"});
			subjectDetail({id: id}).then(({data})=>{
				uni.hideLoading();
				Object.keys(this.params).map(key=>{
					this.params[key] = data[key]==="t"?true:(data[key]==="f"?false:data[key]);
				});
				
				if(this.params.sentiment.includes(0)) this.sentiment_all = true;
				if(this.params.filter_type.includes(0)) this.filter_type_all = true;
				if(this.params.verified_type.includes(0)) this.verified_type_all = true;
				this.params.precision = this.params.precision=="t" ? true : false;
				this.tendOptions.map(item=>{
					if(this.params.sentiment.includes(item.value)){
						item.checked = true;
					}
				});
				this.articleTypeOptions.map(item=>{
					if(this.params.filter_type.includes(item.value)){
						item.checked = true;
					}
				});
				this.weiboUserOptions.map(item=>{
					if(this.params.verified_type.includes(item.value)){
						item.checked = true;
					}
				});
			
				if(this.params.custom_media.includes(0)) this.mediaTypeAll_warn = true;
				if(this.params.custom_type.includes(0)) this.filter_type_all_warn = true;
				if(this.params.custom_sentiment.includes(0)) this.filter_type_all_warn = true;
			});
		}
		let usage = uni.getStorageSync("usage");
		let count = Math.floor(usage.master_limit - usage.master_used);
		this.wordCount = count<0 ? 0 : count;
	},
	onUnload() {
		this.$store.commit("isInputPageInAddHandle", false);
	},
	computed: {
		isInputPage() {
			return this.$store.state.isInputPageInAdd;
		},
		is_word_spacing(){
			return !this.params.word_spacing ? false : true;
		},
		is_brand_pos(){
			return !this.params.brand_pos ? false : true;
		},
	},
	methods: {
		tabChange(val) {
			if(!this.params.word_1.length){
				this.$refs.uToast.show({
					title: "内容不能为空",
					type: "error",
				});
				return;
			}
			this.tabIndex = val;
		},
		checksMediaTypeAll(val) {
			if(val.value){
				this.mediaOptions.map(item=>{
					item.checked = false;
				});
				this.params.filter_media = [0];
			}else{
				this.params.filter_media = [];
			}
		},
		checksMediaType(val) {
			if(val.length == 11){
				this.mediaTypeAll = true;
				this.mediaOptions.map(item=>{
					item.checked = false;
				});
				this.params.filter_media = [0];
			}else{
				this.mediaTypeAll = false;
				this.params.filter_media = val;
			}
		},
		checksTendAll(val) {
			if(val.value){
				this.tendOptions.map(item=>{
					item.checked = false;
				});
			}
			this.params.sentiment = [0];
		},
		checksTend(val) {
			if(val.length == 3){
				this.sentiment_all = true;
				this.tendOptions.map(item=>{
					item.checked = false;
				});
				this.params.sentiment = [0];
			}else{
				this.sentiment_all = false;
				this.params.sentiment = val;
			}
		},
		checksArticleTypeAll(val) {
			if(val.value){
				this.articleTypeOptions.map(item=>{
					item.checked = false;
				});
			}
			this.params.filter_type = [0];
		},
		checksArticleType(val) {
			if(val.length == 4){
				this.filter_type_all = true;
				this.articleTypeOptions.map(item=>{
					item.checked = false;
				});
				this.params.filter_type = [0];
			}else{
				this.filter_type_all = false;
				this.params.filter_type = val;
			}
		},
		checksWeiboUserAll(val) {
			if(val.value){
				this.weiboUserOptions.map(item=>{
					item.checked = false;
				});
			}
			this.params.verified_type = [0];
		},
		checksWeiboUser(val) {
			if(val.length == 3){
				this.verified_type_all = true;
				this.weiboUserOptions.map(item=>{
					item.checked = false;
				});
				this.params.verified_type = [0];
			}else{
				this.verified_type_all = false;
				this.params.verified_type = val;
			}
		},
		checksWarn(val) {
		},
		checksWarnMediaTypeAll(val) {
			if(val.value){
				this.warn_mediaOptions.map(item=>{
					item.checked = false;
				});
			}
			this.params.custom_media = [0];
		},
		checksWarnMediaType(val) {
			if(val.length == 11){
				this.mediaTypeAll_warn = true;
				this.warn_mediaOptions.map(item=>{
					item.checked = false;
				});
				this.params.custom_media = [0];
			}else{
				this.mediaTypeAll_warn = false;
				this.params.custom_media = val;
			}
		},
		checksWarnTendAll(val) {
			if(val.value){
				this.warn_tendOptions.map(item=>{
					item.checked = false;
				});
			}
			this.params.custom_sentiment = [0];
		},
		checksWarnTend(val) {
			if(val.length == 3){
				this.sentiment_all_warn = true;
				this.warn_tendOptions.map(item=>{
					item.checked = false;
				});
				this.params.custom_sentiment = [0];
			}else{
				this.sentiment_all_warn = false;
				this.params.custom_sentiment = val;
			}
		},
		checksWarnArticleTypeAll(val) {
			if(val.value){
				this.warn_articleTypeOptions.map(item=>{
					item.checked = false;
				});
			}
			this.params.custom_type = [0];
		},
		checksWarnArticleType(val) {
			if(val.length == 4){
				this.filter_type_all_warn = true;
				this.warn_articleTypeOptions.map(item=>{
					item.checked = false;
				});
				this.params.custom_type = [0];
			}else{
				this.filter_type_all_warn = false;
				this.params.custom_type = val;
			}
		},
		checksWarnTendAll2(val) {
			if(val.value){
				this.warn_tendOptions2.map(item=>{
					item.checked = false;
				});
			}
			this.params.abnormal_sentiment = [0];
		},
		checksWarnTend2(val) {
			if(val.length == 3){
				this.sentiment_all_warn2 = true;
				this.warn_tendOptions2.map(item=>{
					item.checked = false;
				});
				this.params.abnormal_sentiment = [0];
			}else{
				this.sentiment_all_warn2 = false;
				this.params.abnormal_sentiment = val;
			}
		},
		checksWarnNoise(val) {
			this.params.custom_noise = val;
		},
		toInputPage(type) {
			this.kwType = type;
			switch(type){
				case "品牌词": 
					this.$store.commit("inputPageWordHandle", this.params.word_1.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "主题词": 
					this.$store.commit("inputPageWordHandle", this.params.word_2.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "事件词":
					this.$store.commit("inputPageWordHandle", this.params.word_3.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "歧义词":
					this.$store.commit("inputPageWordHandle", this.params.amb_word.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "排除词":
					this.$store.commit("inputPageWordHandle", this.params.exclude_word.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "排除作者":
					this.$store.commit("inputPageWordHandle", this.params.exclude_author.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "排除域名":
					this.$store.commit("inputPageWordHandle", this.params.exclude_domain.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "排除频道":
					this.$store.commit("inputPageWordHandle", this.params.exclude_channel.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "指定站点":
					this.$store.commit("inputPageWordHandle", this.params.filter_channel.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "指定作者":
					this.$store.commit("inputPageWordHandle", this.params.filter_source.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "信源范围":
					this.$store.commit("inputPageWordHandle", this.params.filter_repost_source.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "地域范围":
					this.$store.commit("inputPageWordHandle", this.params.filter_area.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "预警词":
					this.$store.commit("inputPageWordHandle", this.params.custom_words.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
				case "预警排除词":
					this.$store.commit("inputPageWordHandle", this.params.custom_exclude.map(item=>{
							return {
								label: item,
								check: false
							}
						})
					);
					break;
			}
			this.$store.commit("isInputPageInAddHandle", true);
		},
		getWordData(data) {
			switch(data.type){
				case "品牌词": 
					this.params.word_1 = data.content.split(" ");
					break;
				case "主题词":
					this.params.word_2 = data.content.split(" ");
					break;
				case "事件词":
					this.params.word_3 = data.content.split(" ");
					break;
				case "歧义词": 
					this.params.amb_word = data.content.split(" ");
					break;
				case "排除词":
					this.params.exclude_word = data.content.split(" ");
					break;
				case "排除作者":
					this.params.exclude_author = data.content.split(" ");
					break;
				case "排除域名":
					this.params.exclude_domain = data.content.split(" ");
					break;
				case "排除频道":
					this.params.exclude_channel = data.content.split(" ");
					break;
				case "指定站点":
					this.params.filter_channel = data.content.split(" ");
					break;
				case "指定作者":
					this.params.filter_source = data.content.split(" ");
					break;
				case "信源范围":
					this.params.filter_repost_source = data.content.split(" ");
					break;
				case "指定账号":
					this.params.filter_source_id = data.content.split(" ");
					break;
				case "地域范围":
					this.params.filter_area = data.content.split(" ");
					break;
				case "预警词":
					this.params.custom_words = data.content.split(" ");
					break;
				case "预警排除词":
					this.params.custom_exclude = data.content.split(" ");
					break;
			}
		},
		subcateSelect(index) {
			this.subcateIndex = index;
			this.isSubcate = false;
		},
		save() {
			let params = {...this.params};
			if(!params.title.length){
				this.$refs.uToast.show({
					title: "请输入专题名称",
					type: "error",
				});
			}else if(!params.word_1.length){
				this.$refs.uToast.show({
					title: "请输入品牌词",
					type: "error",
				});
			}else{
				for(let i in params){
					if(params[i] === true) params[i] = "t";
					if(params[i] === false) params[i] = "f";
				}
				uni.showLoading({title: "保存中"});
				if(!params.id){
					addSubject(params).then(({code})=>{
						uni.hideLoading();
						if(code == 200){
							uni.navigateBack({
								delta: 1,
								success: ()=>{
									this.$store.commit('isRefreshSubjectsListHandle', new Date().getTime());
								}
							});
						}
					});
				}else{
					editSubject(params).then(({code})=>{
						uni.hideLoading();
						if(code == 200){
							uni.navigateBack({
								delta: 1,
								success: ()=>{
									this.$store.commit('isRefreshSubjectsListHandle', new Date().getTime());
								}
							});
						}
					});
				}
			}
		}
	}
}
</script>

<style lang="scss">
@import "@/style/newSubject.scss";
</style>
